import tkinter
from feed import CheckFeed
import sys

window = tkinter.Tk()
window.title("Sound Tubtelegramer")
window.config(padx=30, pady=30)
window.minsize(width=500, height=200)

# Labels
intro = tkinter.Label(text="Loading RSS...", pady=70)
# intro.config(text="This is new text")
intro.grid(column=1, row=0)

v_text = tkinter.Label(text="Количество видео:")
# intro.config(text="This is new text")
v_text.grid(column=0, row=1)

# Spinbox


def spinbox_used():
    # gets the current value in spinbox.
    print(spinbox.get())


spinbox = tkinter.Spinbox(from_=5, to=10, width=5, command=spinbox_used)
spinbox.grid(column=2, row=1)

yt_feed = CheckFeed()
videos = yt_feed.read()


intro.config(
    text="Выбери видео из списка и кликни 'Скачать':", pady=5, font=("bold"))


# Radiobutton
def radio_used():
    dl_button["state"] = "normal"


# Variable to hold on to which radio button value is checked.
list_of_videos = tkinter.IntVar()
for i in range(int(spinbox.get())):
    radiobutton = tkinter.Radiobutton(
        text=videos[i]['title'], value=i+1, variable=list_of_videos, command=radio_used)
    radiobutton.grid(column=1, row=2+i)

# Buttons


def get_mp3():
    item = list_of_videos.get()
    print(videos[item - 1]["link"])


# calls action() when pressed
dl_button = tkinter.Button(
    text="Скачать mp3", command=get_mp3, state="disabled")
dl_button.grid(column=1, row=int(spinbox.get()) + 3)


refresh_btn = tkinter.Button(
    text="Обновить видео", command=get_mp3)
refresh_btn.grid(column=0, row=int(spinbox.get()) + 3)

re_btn = tkinter.Button(
    text="Выйти из программы", command=sys.exit)
re_btn.grid(column=2, row=int(spinbox.get()) + 3)


window.mainloop()
